package com.fy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fy.pojo.entity.User;
import com.fy.pojo.vo.user.UserSpaceVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    //根据名字查询用户
    @Select("select user.total_space,use_space from user where username=#{username}")
    UserSpaceVO selectSpaceByUserName(String username);

    //根据用户id更新空间使用信息
    @Update("update user set use_space = #{useSpace} where user_id=#{userId};")
    void updateSpaceByUserId(Integer userId, Long useSpace);

    //根据用户名查询用户
    @Select("select * from user where username=#{nickName};")
    Integer selectUserIdByName(String nickName);

    //根据id更新用户账号状态
    @Update("update user set status=#{status} where user_id=#{userId}")
    void updateStatusById(int userId,int status);

    //根据用户名分配空间
    @Update("update user set total_space=#{changeSpace} where username=#{nickName}")
    void updateTotalSpaceByName(String nickName, long changeSpace);

    //获取用户已经使用的空间信息
    @Select("select sum(use_space) from user;")
    Long getTotalUseSpace();
}
